%--------------------------------------------------------------------------
% computes the eigenvalues of the linearized problem using a 'frozen time'
% approach
%
% assumes the basic state is in the t = O(1 / delta) regime
%--------------------------------------------------------------------------


function [L] = lo_comp_adj(kk, M)

addpath ../
p = params;
N = p.N;

z = linspace(0, 1, N);
h = z(2) - z(1);

L = spalloc(N, N, 4 * N);


for j = 1:length(kk)
    
    k = kk(j);
        
    if k > 1e-4
        w = @(z)  -(((-z + 1) * sinh(k) + z * cosh(k) * k) .* sinh(k * z) - k * sinh(k) * z .* cosh(k * z)) * M * k / (-0.2e1 * cosh(k) * sinh(k) + 0.2e1 * k);
    else
        w = @(z) -k ^ 2 * (z - 1) .* M .* (0.280e3 + ((z .^ 4) - 0.4e1 / 0.3e1 * z - 0.4e1 / 0.3e1 * (z .^ 3) + 0.10e2 / 0.3e1 * (z .^ 2) + 0.1e1) * k ^ 4 + (-0.56e2 / 0.3e1 * z + 0.28e2 + (28 * z .^ 2)) * k ^ 2) .* (z .^ 2) / 0.1120e4;
    end
    
    for i = 1:N
        
        if(i == 1)
            L(i,i) = -2 / h^2 - k^2;
            L(i,i+1) = 2 / h^2;
        elseif (i == N)
            L(i,1) = w(z(1)) * z(i);
            L(i,2:N-2) = 2 * w(z(2:N-2)) .* z(2:N-2);
            L(i,N-1) = 2 / h^2 + 2 * w(z(N-1)) * z(N-1);
            L(i,i) = -2 / h^2 - k^2 + w(z(i)) * z(i);
        else
            L(i,i) = -2 / h^2 - k^2;
            L(i,i-1) = 1 / h^2;
            L(i,i+1) = 1 / h^2;
        end
    end
    
    
end